Single Number
Given an array of integers, every element appears twice except for one.
Find that single one.
Note:
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
题目大意:给定一个数组,只有一个数出现过1次,其余均出现过2次,找出出现过一次的数
题目难度:Medium
/**
* Created by gzdaijie on 16/6/15
*/
public class Solution {
public int singleNumber(int[] nums) {
int result = 0;
for (int i = 0; i < nums.length; i++) {
result ^= nums[i];
}
return result;
}
}